package cn.kill.service.impl;

import cn.jbit.entity.User;
import cn.kill.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 源码学院只为培养优秀的bat程序员而生
 *
 * @author 学员张在成
 * @data 2021/6/20
 */
@Service
@Slf4j
public class LoginServiceImpl implements UserDetailsService {

    @Autowired
    private UserService  userService;


    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {

        //查询数据库
        User user = userService.getByUsername(s);

        if (user==null){
            log.warn("没有获取到该用户信息");
        }

        log.info("根据用户名{},获取到该用户信息{}",s,user);

        return user;
    }



}
